package cn.iocoder.yudao.module.trade.delivery.vo;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.region.RegionUtils;
import cn.iocoder.yudao.framework.region.enums.RegionDataSet;
import cn.iocoder.yudao.framework.region.vo.AddressVO;
import cn.iocoder.yudao.module.trade.delivery.dal.dataobject.DeliveryPickUpStoreDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Schema(description = "用户 App - 自提门店 Response VO")
@Data
public class AppDeliveryPickUpStoreRespVO extends AddressVO {

    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23128")
    private Long id;

    @Schema(description = "店铺编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
    private Long shopId;

    @Schema(description = "门店名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
    private String name;

    @Schema(description = "门店徽标", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://exmaple.local/1.png")
    private String logo;

    @Schema(description = "门店手机", requiredMode = Schema.RequiredMode.REQUIRED, example = "1528516029")
    private String phone;

    @Schema(description = "区域编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18733")
    private Integer areaId;

    @Schema(description = "距离，单位：千米", example = "100") // 只有在用户传递了经纬度时，才进行计算
    private Double distance;

    public static AppDeliveryPickUpStoreRespVO fromDO(DeliveryPickUpStoreDO store) {
        AppDeliveryPickUpStoreRespVO respVO = BeanUtils.toBean(store, AppDeliveryPickUpStoreRespVO.class);
        respVO.setCountyCode(RegionUtils.convertRegionIdToCode(store.getAreaId()));
        RegionUtils.autoAssignCounty(RegionDataSet.ONLY_LATEST, respVO.getCountyCode(), respVO);
        return respVO;
    }

}
